package com.webfinal.backsystem.controller;

import com.webfinal.backsystem.request.order.*;
import com.webfinal.backsystem.response.order.*;
import com.webfinal.backsystem.service.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
public class OrderController {

    private static Logger LOG= LoggerFactory.getLogger(OrderController.class);

    @Autowired
    private OrderService orderService;

    @RequestMapping(value = "/api/order/placeorder")
    public PlaceOrderResponse placeOrder(@RequestBody PlaceOrderRequest request){
        PlaceOrderResponse response = new PlaceOrderResponse();
        try {
            response=orderService.placeOrder(request);
        }catch (Exception e){
            response.setResultCode("1");
            response.setResultMsg(e.getMessage());
            LOG.error(e.getMessage());
        }
        return response;
    }

    @RequestMapping(value = "/api/order/orderpay")
    public OrderPayResponse orderPay(@RequestBody OrderPayRequest request){
        OrderPayResponse response = new OrderPayResponse();
        try {
            response=orderService.orderPay(request);
        } catch (Exception e) {
            response.setResultCode("1");
            response.setResultMsg(e.getMessage());
            LOG.error(e.getMessage());
            e.printStackTrace();
        }
        return response;
    }

    @RequestMapping(value = "/api/order/delivergoods")
    public DeliverGoodsResponse deliverGoods(@RequestBody DeliverGoodsRequest request){
        return orderService.deliverGoods(request);
    }

    @RequestMapping(value = "/api/order/takedelivery")
    public TakeDeliveryResponse takedelivery(@RequestBody TakeDeliveryRequest request){
        return orderService.takeDelivery(request);
    }
    @RequestMapping(value = "/api/order/refundapply")
    public RefundApplyResponse refundApply(@RequestBody RefundApplyRequest request){
        return orderService.refundApply(request);
    }

    @RequestMapping(value = "/api/order/refundaudit")
    public RefundApplyResponse refundAudit(@RequestBody RefundAuditRequest request){
        return orderService.refundAudit(request);
    }

    @RequestMapping(value = "/api/order/refund")
    public RefundResponse refund(RefundRequest request){
        return orderService.refund(request);
    }

    @RequestMapping(value = "/api/order/queryorder")
    public QueryOrderResponse queryOrder(@RequestBody QueryOrderRequest request){
        return orderService.queryOrder(request);
    }

    @RequestMapping(value = "/api/order/deliverOrder")
    public OrderinfoResponse deliverOrder(){
        OrderinfoResponse response = orderService.deliverOrder();
        return response;
    }

    @RequestMapping(value = "/api/order/refundAuditOrder")
    public OrderinfoResponse refundAuditOrder(){
        OrderinfoResponse response = orderService.refundAuditOrder();
        return response;
    }

    @RequestMapping(value = "/api/order/refundOrder")
    public OrderinfoResponse refundOrder(){
        OrderinfoResponse response = orderService.refundOrder();
        return response;
    }

    @RequestMapping(value = "/api/order/updatedeliver")
    public UpdateOrderDetailResponse updatedeliver(@RequestBody UpdateOrderDetailRequest updateOrderDetailRequest){
        return orderService.updatedeliverOrder(updateOrderDetailRequest);
    }

    @RequestMapping(value = "/api/order/updaterefundAudit")
    public UpdateOrderDetailResponse updaterefundAudit(@RequestBody UpdateOrderDetailRequest updateOrderDetailRequest){
        return orderService.updaterefundAuditOrder(updateOrderDetailRequest);
    }

    @RequestMapping(value = "/api/order/updaterefund")
    public UpdateOrderDetailResponse updaterefund(@RequestBody UpdateOrderDetailRequest updateOrderDetailRequest){
        return orderService.updaterefundOrder(updateOrderDetailRequest);
    }

    @RequestMapping(value = "/api/order/searchorderbyusername")
    public SearchOrderResponse serchorder(@RequestBody SearchOrderRequest searchOrderRequest){
        return orderService.searchorder(searchOrderRequest);
    }

    @RequestMapping(value = "/api/order/orderproducts")
    public OrderProductsResponse orderproducts(@RequestBody OrderProductsResquest orderProductsResquest){
        return orderService.orderproducts(orderProductsResquest);
    }

    @RequestMapping(value = "/api/order/allorderproducts")
    public OrderProductsResponse allorderproducts(){
        return orderService.orderproductsall();
    }
}
